﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pata.SylkSharp.Core.Bll
{
    /// <summary>
    /// Enumerates the possible fields in a <see cref="BRecord"/>
    /// </summary>
    public enum BRecordFieldType
    {
        /// <summary>
        /// tells maximum number of columns
        /// </summary>
        X,
        /// <summary>
        /// tells maximum number of rows
        /// </summary>
        Y,
        /// <summary>
        /// Unknown field type.
        /// </summary>
        Unknown = 100
    }

    /// <summary>
    /// Object representation of field of a Sylk record of type 'B'
    /// </summary>
    public class BRecordField : FieldBase<BRecordFieldType>
    {
        /// <summary>
        /// Instanciate a new <see cref="BRecordField"/>
        /// </summary>
        public BRecordField()
            : base(BRecordFieldType.Unknown, String.Empty) { }

        /// <summary>
        /// Instanciate a new <see cref="BRecordField"/>
        /// </summary>
        /// <param name="pType">Type of this field.</param>
        /// <param name="pValue">The value contained by this field.</param>
        public BRecordField(BRecordFieldType pType, string pValue)
            : base(pType, pValue) { }
    }

    /// <summary>
    /// Object representation of a Sylk record of type 'B'.
    /// Tells number of rows and columns in the spreadsheet.
    /// Recommended that it come before C and F records
    /// </summary>
    public class BRecord : RecordBase<BRecordField, BRecordFieldType>
    {
        private static readonly BRecordFieldType[] _MANDATORY_FIELDS = new BRecordFieldType[] { BRecordFieldType.X, BRecordFieldType.Y };

        /// <summary>
        /// Instanciate a new <see cref="BRecord"/>
        /// </summary>
        public BRecord(string pLineWithoutId)
            : base(RecordType.B, pLineWithoutId, BRecordFieldType.Unknown) { }

        /// <summary>
        /// Get mandatory fields for this record.
        /// </summary>
        /// <returns></returns>
        public override System.Collections.Generic.IEnumerable<BRecordFieldType> GetMandatoryFields()
        {
            return _MANDATORY_FIELDS;
        }

        /// <summary>
        /// Get the default field type.
        /// </summary>
        /// <returns></returns>
        public override BRecordFieldType GetUnknownFieldType()
        {
            return BRecordFieldType.Unknown;
        }
    }
}
